import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { BaseItem } from "../../common/BaseItem";
import { ItemData } from "../../../resource/info/ItemData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { MoneyUtil } from "../../common/util/MoneyUtil";
type int = number;
//class SellItemCellRenderer
    
    export  class SellItemCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initStyles();
            this.initView();
            this.addListeners();
            return;
        }

        /* internal  */initStyles(): void
        {
            this.setStyle("downSkin", GlobalClass.getBitmap("StallItemOver"));
            this.setStyle("overSkin", GlobalClass.getBitmap("StallItemOver"));
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", GlobalClass.getBitmap("StallItemOver"));
            this.setStyle("selectedOverSkin", GlobalClass.getBitmap("StallItemOver"));
            this.setStyle("selectedUpSkin", GlobalClass.getBitmap("StallItemOver"));
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=ObjCreate.createBg(0, 0, 158, 38, this, "DisabledBg");
            var loc2=GlobalClass.getBitmap("PackItemBg");
            this.addChild(loc2);
            this._tfItemName = ObjCreate.createTextField("", 40, 2, 110, 20, this);
            this._tfItemName.mouseEnabled = false;
            this._tfSinglePrice = ObjCreate.createTextField(Language.getString(40805), 40, 20, 35, 20, this);
            this._tfSinglePrice.mouseEnabled = false;
            this._tfPrice = ObjCreate.createTextField("", 75, 20, 60, 20, this);
            this._tfPrice.mouseEnabled = false;
            this._bmpIcon = new Object /* flash.display.Bitmap */();
            this._bmpIcon.x = 135;
            this._bmpIcon.y = 21;
            this.addChild(this._bmpIcon);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(32, 32);
            this._baseItem.x = 3;
            this._baseItem.y = 3;
            this._baseItem.doubleClickEnabled = true;
            this.addChild(this._baseItem);
            return;
        }

        /* internal  */addListeners(): void
        {
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.ROLL_OVER, this.overHandler);
            this.addEventListener(flash.events.MouseEvent.ROLL_OUT, this.outHandler);
            this.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.dblClickHandler);
            return;
        }

        /* internal  */dblClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (data && data is ItemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.StallFastOp, data));
            }
            return;
        }

        /* internal  */overHandler(arg1: Object /* flash.events.Event */=null): void
        {
            if (this._currentState == SellItemCellRenderer.SELECTED) 
            {
                return;
            }
            this._currentState = SellItemCellRenderer.OVER;
            this.changeToState(SellItemCellRenderer.OVER);
            return;
        }

        /* internal  */outHandler(arg1: Object /* flash.events.Event */=null): void
        {
            if (this._currentState == SellItemCellRenderer.SELECTED) 
            {
                return;
            }
            this._currentState = SellItemCellRenderer.OUT;
            this.changeToState(SellItemCellRenderer.OUT);
            return;
        }

        /* internal  */selectHandler(arg1: Object /* flash.events.Event */=null): void
        {
            this._currentState = selected ? SellItemCellRenderer.SELECTED : SellItemCellRenderer.OUT;
            if (this._currentState == SellItemCellRenderer.SELECTED) 
            {
                this.changeToState(this._currentState);
            }
            return;
        }

        /* internal  */changeToState(arg1: int): void
        {
            if (this._stateStyle && this._stateStyle.parent) 
            {
                flash.ui.Mouse.cursor = flash.ui.MouseCursor.AUTO;
                if (SellItemCellRenderer._overTarget == this && this._currentState == SellItemCellRenderer.SELECTED || SellItemCellRenderer._overTarget == this && !(SellItemCellRenderer._clickTarget == this) && this._currentState == SellItemCellRenderer.OUT) 
                {
                    this._stateStyle.parent.removeChild(this._stateStyle);
                }
            }
            var loc1=arg1;
            switch (loc1) 
            {
                case SellItemCellRenderer.SELECTED:
                {
                    if (!SellItemCellRenderer._stallItemSelected) 
                    {
                        SellItemCellRenderer._stallItemSelected = GlobalClass.getBitmap("StallItemOver");
                        SellItemCellRenderer._stallItemSelected.width = 128;
                    }
                    this._stateStyle = SellItemCellRenderer._stallItemSelected;
                    this._stateStyle.x = 30;
                    flash.ui.Mouse.cursor = flash.ui.MouseCursor.ARROW;
                    if (this.numChildren > 0) 
                    {
                        this.addChildAt(this._stateStyle, 1);
                    }
                    SellItemCellRenderer._clickTarget = this;
                    break;
                }
                case SellItemCellRenderer.OVER:
                {
                    if (!SellItemCellRenderer._stallItemOver) 
                    {
                        SellItemCellRenderer._stallItemOver = GlobalClass.getBitmap("StallItemOver");
                        SellItemCellRenderer._stallItemOver.width = 128;
                    }
                    this._stateStyle = SellItemCellRenderer._stallItemOver;
                    this._stateStyle.x = 30;
                    flash.ui.Mouse.cursor = flash.ui.MouseCursor.ARROW;
                    if (this.numChildren > 0) 
                    {
                        this.addChildAt(this._stateStyle, 1);
                    }
                    SellItemCellRenderer._overTarget = this;
                    break;
                }
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            this.selectHandler();
            return;
        }

        /* internal  */clear(): void
        {
            this._itemData = null;
            this._baseItem.itemData = this._itemData;
            if (this._baseItem.parent) 
            {
                this._baseItem.parent.removeChild(this._baseItem);
            }
            if (this._tfItemName.parent) 
            {
                this._tfItemName.parent.removeChild(this._tfItemName);
            }
            if (this._tfSinglePrice.parent) 
            {
                this._tfSinglePrice.parent.removeChild(this._tfSinglePrice);
            }
            if (this._tfPrice.parent) 
            {
                this._tfPrice.parent.removeChild(this._tfPrice);
            }
            if (this._bmpIcon.parent) 
            {
                this._bmpIcon.parent.removeChild(this._bmpIcon);
            }
            return;
        }

        /* internal  */addToView(): void
        {
            this.addChild(this._baseItem);
            this.addChild(this._tfItemName);
            this.addChild(this._tfSinglePrice);
            this.addChild(this._tfPrice);
            this.addChild(this._bmpIcon);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof arg1 === "itemdata") 
            {
                this._itemData = arg1 as ItemData;
                this.addToView();
                this._baseItem.itemData = this._itemData;
                this._baseItem.isDragAble = false;
                this._baseItem.toolTipType = ItemData.ToolTipType_Pack;
                this._tfItemName.htmlText = HTMLUtil.addColor(this._itemData.itemInfo.item.name, ColorConfig.instance.getItemColor(this._itemData.itemInfo.item.color).color);
                this.updatePrice(this._itemData.itemExInfo.stall_gold, this._itemData.itemExInfo.stall_coin);
                return;
            }
            this.clear();
            return;
        }

        /* internal  */updatePrice(arg1: int, arg2: int): void
        {
            if (arg1 > 0) 
            {
                this._tfPrice.htmlText = MoneyUtil.getGoldHtml(arg1);
                this._bmpIcon.bitmapData = GlobalClass.getBitmapData("Yuanbao_small");
            }
            else if (arg2 > 0) 
            {
                this._tfPrice.htmlText = MoneyUtil.getCoinHtml(arg2);
                this._bmpIcon.bitmapData = GlobalClass.getBitmapData("Tongqian_small");
            }
            return;
        }

        public RefreshPrice(arg1: int, arg2: int): void
        {
            return;
        }

        /* internal */ static /* const */OUT: int=0;

        /* internal */ static /* const */OVER: int=1;

        /* internal */ static /* const */SELECTED: int=2;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_tfItemName: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfSinglePrice: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfPrice: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_stateStyle: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_currentState: int;

        /* internal */ static /* var */_overTarget: SellItemCellRenderer;

        /* internal */ static /* var */_clickTarget: SellItemCellRenderer;

        /* internal */ static /* var */_stallItemSelected: Object /* flash.display.Bitmap */;

        /* internal */ static /* var */_stallItemOver: Object /* flash.display.Bitmap */;
    }
